package lib.toolbar.activity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import hd.util.activity.TitleBarActivity;
import lib.toolbar.widget.SideBarView;

/**
 * with SideBar and ToolBar
 * <p/>
 * Created by Haidy on 15/3/3.
 */
public class SideBarToolBarActivity extends ToolBarActivity {

    /**
     * Consists of to parts, include SidebarView and ContentView(BodyView)
     * 由两部分组成，包括SidebarView和ContentView（BodyView）
     */
    private View sideBarView;
    private SideBarView sideBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        sideBar = new SideBarView(this);
        ((ViewGroup) view.getParent()).removeView(view);
        setContentView(sideBar);
        sideBar.setContentView(view);
        sideBarView = new View(this);
        sideBar.setSidebarView(sideBarView);
        sideBar.setOnStatueChangeListener(new SideBarView.OnStatueChangeListener() {
            @Override
            public void onChange(boolean open) {
                onStatueChanged(open);
            }
        });
    }

    /**
     * Sidebar改变状态时
     *
     * @param open 是否打开
     */
    public void onStatueChanged(boolean open) {
    }

    public void setSideBarView(int layout) {
        setSideBarView(View.inflate(this, layout, null));
    }

    public void setSideBarView(View view) {
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        sideBar.setSidebarView(view);
    }

    /**
     * 获取侧边栏View
     *
     * @return view
     */
    public View getSideBar() {
        return sideBar.getSidebarView();
    }

    public void open() {
        sideBar.open();
    }

    public void close() {
        sideBar.close();
    }

    public boolean isOpen() {
        return sideBar.isOpen();
    }

}
